package IOStream;

import java.io.*;

/*
    想要某个属性不被序列化和反序列化
 */
public class SerializableDemo2 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student student1=new Student("hu",20);
        ObjectOutputStream oos=new ObjectOutputStream(
                                new FileOutputStream(
                                new File("C:\\IOStream\\student.ser")));
        oos.writeObject(student1);
        oos.close();
        ObjectInputStream ois=new ObjectInputStream(
                            new FileInputStream(
                            new File("c:\\IOStream\\student.ser")));
        Student student2=(Student) ois.readObject();
        ois.close();
        System.out.println(student1);
        System.out.println(student2);
    }
}
class Student implements Serializable {
    static double PI=3.14;      //这个属性将不被序列化
    transient double E=2.73;       //这个属性也不被序列化
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "E=" + E +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
